package com.gnerv.pabu.basic.core.controller;

import com.gnerv.pabu.basic.core.dto.SessionDTO;
import com.gnerv.pabu.basic.core.entity.Result;
import com.gnerv.pabu.basic.core.service.ISessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 基础平台-session controller
 *
 * @author zhang
 * @date 2019/12/4
 **/
@Api(tags = "会话 管理")
@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/api/manage/session")
public class SessionController {


    @Resource
    private ISessionService sessionService;

    @ApiOperation("注销 会话")
    @RequestMapping(value = "/logout/{sessionId}", method = RequestMethod.GET)
    private Result logout(@PathVariable("sessionId") String sessionId) {
        sessionService.logout(sessionId);
        return new Result();
    }

    @ApiOperation("查询 会话列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result listSession() {
        List<SessionDTO> sessions = sessionService.listSession();
        return new Result().data("sessions", sessions);
    }
}
